﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Buffalo.Lib.Common" %>
<%@ Import Namespace="Buffalo.SMECommon.DAL.Models" %>
<%@ Import Namespace="Buffalo.SMECommon.DAL" %>
<%@ Import Namespace="Buffalo.Web.Areas.SMECommon" %>
 

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string IDOrgUnit = Util.ToSafeString(ViewData["IDOrgUnit"]);
            string criteria = Util.ToSafeString(ViewData["Criteria"]);
            string searchText = Util.ToSafeString(ViewData["SearchText"]);

            string excelTemplateFile = CommonManager.GetModuleFolder() + @"\Template\TemplateProfile.xls";
            string connectionString = ConfigurationManager.ConnectionStrings[GeneralConstant.CONNECTION_STRING].ConnectionString;
            string excelFullFile = new EmployeeDAL().ExportEmployeeToExcel(CommonManager.GetModuleFolder(), excelTemplateFile, GeneralConstant.CONNECTION_STRING, IDOrgUnit, criteria, searchText);

            lnkOutput.Text =  "Output";
            
            string excelFile = Path.GetFileName(excelFullFile);
            lnkOutput.NavigateUrl = @"~\Areas\SMECommon\Temp\" + excelFile;
        }
    }
</script>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <ext:Viewport ID="mainViewPort" runat="server" Layout="fit">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Border="false" Layout="fit">
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnClose" runat="server" Text="Close" Icon="DoorOut">
                                <Listeners>
                                    <Click Handler="parent.ExportExcelWindow.hide();" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Items>
                    <ext:TabPanel ID="TourTabPanel" runat="server" Border="false" LayoutOnTabChange="true">
                        <Items>
                            <ext:Panel ID="panExportExcel" runat="server" Title="Export excel" Padding="6" Layout="fit">
                                <Items>
                                    <ext:FormPanel ID="ExportExcelForm" runat="server" Border="false" >
                                        <Items>
                                            <ext:Container ID="Container1" runat="server" Flex="1">
                                                <Items>
                                                    <ext:HyperLink ID="lnkOutput" runat="server" FieldLabel ="Output: " />
                                                </Items>
                                            </ext:Container>
                                        </Items>
                                    </ext:FormPanel>
                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:TabPanel>
                </Items>
            </ext:Panel>

        </Items>

    </ext:Viewport>
</body>
</html>

